package com.rockxin.cat.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.orhanobut.logger.Logger;
import com.rockxin.cat.R;
import com.rockxin.cat.activity.ActiveInfoActivity;
import com.rockxin.cat.activity.ActiveListActivity;
import com.rockxin.cat.activity.FindMiddleActivity;
import com.rockxin.cat.activity.IntroActivity;
import com.rockxin.cat.activity.PlatformNoticeActivity;
import com.rockxin.cat.activity.RunReportActivity;
import com.rockxin.cat.activity.SafetyGuaranteeActivity;
import com.rockxin.cat.adapter.FindAdapter;
import com.rockxin.cat.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * <b>类名称：    FindFragment             <br/>
 * <b>类描述：                        <br/>
 * <b>创建人：    Lans               <br/>
 * <b>创建时间：  2018/3/1 13:12     <br/>
 * <b>修改人：                        <br/>
 * <b>修改时间：                      <br/>
 * <b>修改备注：                      <br/>
 *
 * @version 1.0.0 <br/>
 */
public class FindFragment extends BaseFragment {
    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.recyler_view)
    RecyclerView recylerView;

    private Unbinder unbinder;

    private List<String> mList;
    private FindAdapter mAdapter;

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    public static FindFragment newInstance() {
        Bundle args = new Bundle();
        FindFragment fragment = new FindFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View mView = inflater.inflate(R.layout.fragment_find, container, false);
        unbinder = ButterKnife.bind(this, mView);
        initView();
        initRecyclerView();
        setListener();
        getData();
        return mView;
    }

    public void initView() {
        backImg.setVisibility(View.GONE);
        title.setText("岩鑫贷");

    }

    private void initRecyclerView() {
        mList = new ArrayList<>();
        mList.add("http://p2.wmpic.me/article/2017/02/23/1487816929_mLwPeYbD.jpg");
        mList.add("http://p2.wmpic.me/article/2017/02/23/1487816929_mLwPeYbD.jpg");
        mList.add("http://p2.wmpic.me/article/2017/02/23/1487816929_mLwPeYbD.jpg");
        mList.add("http://p2.wmpic.me/article/2017/02/23/1487816929_mLwPeYbD.jpg");

        mAdapter = new FindAdapter(R.layout.item_active_list, mList);
        mAdapter.addHeaderView(getHeaderView());
        recylerView.setAdapter(mAdapter);

        final LinearLayoutManager mLayoutManager = new LinearLayoutManager(getContext());
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recylerView.setLayoutManager(mLayoutManager);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                Address data = (Address) adapter.getItem(position);
                Logger.d("onItemClick---position:" + position);
                Intent intent = new Intent(mContext, ActiveInfoActivity.class);
                startActivity(intent);
            }
        });
    }

    private View getHeaderView() {
        View view = getLayoutInflater().inflate(R.layout.item_find_head, (ViewGroup) recylerView.getParent(), false);
        ((RelativeLayout) view.findViewById(R.id.rl_one)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Logger.d("rl_one");
                startEvent(PlatformNoticeActivity.class);
            }
        });
        ((RelativeLayout) view.findViewById(R.id.rl_two)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Logger.d("rl_two");
                startEvent(IntroActivity.class);
            }
        });
        ((RelativeLayout) view.findViewById(R.id.rl_three)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Logger.d("rl_three");
                startEvent(SafetyGuaranteeActivity.class);
            }
        });
        ((RelativeLayout) view.findViewById(R.id.rl_four)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Logger.d("rl_four");
                startEvent(FindMiddleActivity.class);
            }
        });
        ((TextView) view.findViewById(R.id.tv_seemore)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Logger.d("hot_more");
                startEvent(ActiveListActivity.class);
            }
        });
        return view;
    }

    private void setListener() {

    }

    private void getData() {

    }

    private void startEvent(Class cls) {
        Intent intent = new Intent(mContext, cls);
        startActivity(intent);
    }
}
